<script >
import axios from "axios";

export default {
  data() {
    return {
      user:{},
      userxx:{},
      balance:null,
    };
  },
  methods: {
    jilu(){
      this.$router.push({ path: '/jilu' })
    },
    tixian(){
      if (  this.userxx.balance-this.balance<0){
        this.$message.error('提现金额不能超过余额')
      return;
      }
      this.userxx.balance= this.userxx.balance-this.balance;
      axios.post('play/play/update', this.userxx).then(response => {
        this.$message.success('提现成功')
        this.$router.push({ path: '/mine' });
      }).catch(error => {
        console.error('Error fetching player:', error);
        this.error = error;
      })
    },
  },
  created() {
    this.user.id =  JSON.parse(sessionStorage.getItem('id'));
    const a = this.$route.query.a;
    if (a) {
      this.userxx = JSON.parse(a);
    }
  },
};
</script>

<template>
  <div class="withdrawal-container">
    <h2>提现</h2>
    <p>可提现金额(元) <span>¥{{userxx.balance}}</span></p>
    <div class="withdrawal-amount">
      <label for="amount">提现金额</label>
      <input type="number" id="amount" v-model="balance" placeholder="请输入提现金额"></input>
    </div>
    <div class="withdrawal-method">
      <label for="method">提现方式</label>
      <span class="method-selected">微信 <i class="checkmark">&#10003;</i></span>
    </div>
    <button class="withdraw-now" @click="tixian">立即提现</button>
    <a href="#" class="withdrawal-records" @click="jilu">提现记录</a>
  </div>
</template>

<style >
.withdrawal-container {
  width: 300px;
  padding: 20px;
  border: 1px solid #ccc;
  border-radius: 5px;
  margin-left: 40px;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}

h2 {
  text-align: center;
}

p {
  text-align: center;
  margin: 10px 0;
}

.withdrawal-amount {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.withdrawal-method {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.method-selected {
  color: green;
}

.checkmark {
  margin-left: 5px;
}

.withdraw-now {
  background-color: #007BFF;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 5px;
  width: 100%;
  cursor: pointer;
}

.withdrawal-records {
  display: block;
  text-align: center;
  margin-top: 10px;
  text-decoration: none;
  color: #007BFF;
}
</style>
